﻿using System;
using Styx;
using Styx.Helpers;
using Styx.Pathing;
using Styx.TreeSharp;
using Styx.WoWInternals.WoWObjects;
using Action = Styx.TreeSharp.Action;

namespace TuanHA_Combat_Routine
{
    public partial class Classname
    {
        #region Delegates

        public delegate float DynamicRangeRetriever(object context);

        public delegate WoWPoint LocationRetriever(object context);

        public delegate bool SimpleBooleanDelegate(object context);

        public delegate WoWUnit UnitSelectionDelegate(object context);

        #endregion

        //private static DateTime DoNotMove;

        private static Composite MovementMoveStop(UnitSelectionDelegate toUnit, double range)
        {
            return new Decorator(ret => ((((THSettings.Instance.AutoMove && !IsOverrideModeOn) && ((toUnit != null) && (toUnit(ret) != null))) && (((toUnit(ret) != Me) && toUnit(ret).IsAlive) && (IsMoving(Me) && IsEnemy(toUnit(ret))))) && (GetDistance(toUnit(ret)) <= range)) && InLineOfSpellSightCheck(toUnit(ret)), new Styx.TreeSharp.Action(delegate(object ret)
            {
                Navigator.PlayerMover.MoveStop();
                return RunStatus.Failure;
            }));
        }

        private static Composite MovementMoveToLoS(UnitSelectionDelegate toUnit)
        {
            return new Decorator(delegate(object ret)
            {
                if (((!THSettings.Instance.AutoMove || IsOverrideModeOn) || (Me.IsCasting || (toUnit == null))) || (((toUnit(ret) == null) || (toUnit(ret) == Me)) || (!toUnit(ret).IsAlive || !IsEnemy(toUnit(ret)))))
                {
                    return false;
                }
                if (GetDistance(toUnit(ret)) <= 30f)
                {
                    return !InLineOfSpellSightCheck(toUnit(ret));
                }
                return true;
            }, new Styx.TreeSharp.Action(delegate(object ret)
            {
                Navigator.MoveTo(toUnit(ret).Location);
                return RunStatus.Failure;
            }));
        }

        private static Composite MovementMoveToMelee(UnitSelectionDelegate toUnit)
        {
            return new Decorator(ret => (((THSettings.Instance.AutoMove && !IsOverrideModeOn) && (!Me.IsCasting && (toUnit != null))) && (((toUnit(ret) != null) && (toUnit(ret) != Me)) && (toUnit(ret).IsAlive && IsEnemy(toUnit(ret))))) && (GetDistance(toUnit(ret)) > 3f), new Styx.TreeSharp.Action(delegate(object ret)
            {
                Navigator.MoveTo(toUnit(ret).Location);
                return RunStatus.Failure;
            }));
        }

        public Composite MovementMoveBehind(UnitSelectionDelegate toUnit)
        {
            return new Decorator(delegate(object ret)
            {
                if ((((!THSettings.Instance.AutoMove || IsOverrideModeOn) || (Me.IsCasting || (toUnit == null))) || (((toUnit(ret) == null) || (toUnit(ret) == Me)) || (!toUnit(ret).IsAlive || (GetDistance(toUnit(ret)) > 5f)))) || Me.IsBehind(toUnit(ret)))
                {
                    return false;
                }
                return toUnit(ret).IsPlayer || ((!toUnit(ret).IsPlayer && (toUnit(ret).CurrentTarget != Me)) && toUnit(ret).Combat);
            }, new Styx.TreeSharp.Action(delegate(object ret)
            {
                Navigator.MoveTo(toUnit(ret).Location.RayCast(toUnit(ret).Rotation + WoWMathHelper.DegreesToRadians(150f), 3f));
                return RunStatus.Failure;
            }));
        }
    }
}